package cn.edu.cug.cs.gtl.docsrv.auth.service.imp;

import cn.edu.cug.cs.gtl.docsrv.auth.dao.UserDao;
import cn.edu.cug.cs.gtl.docsrv.auth.service.UserService;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthUser;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;

    @Override
    public boolean insertUser(String authUserJSON) {
        AuthUser authUser = JSON.parseObject(authUserJSON, AuthUser.class);
        if(authUser!=null)
            return userDao.insertUser(authUser);
        else
            return false;
    }

    @Override
    public boolean updateUser(String authUserJSON) {
        AuthUser authUser = JSON.parseObject(authUserJSON, AuthUser.class);
        if(authUser!=null)
            return userDao.updateUser(authUser);
        else
            return false;
    }

    @Override
    public boolean deleteUser(String authUserName) {
        return userDao.deleteUser(authUserName);
    }

    @Override
    public String getUser(String authUserName) {
        AuthUser authUser = userDao.getUser(authUserName);
        return JSON.toJSONString(authUser);
    }
}
